<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui">
<ui:composition template="/pages/template.xhtml">
	<ui:define name="titulo">
		<h:outputText value="#{msgs['titulo.cadastro.modalidades']}" />
	</ui:define>
	<ui:define name="corpo">
		<h:form id="formModalidade">
			<p:panelGrid border="1" cellpadding="10">
				<p:row>
					<p:column>
						<h:outputLabel for="nome"
							value="#{msgs['form.label.modalidade.nome']}" />
					</p:column>
					<p:column>
						<p:inputText id="nome"
							value="#{ModalidadeController.modalidade.nome}" required="true"
							requiredMessage="#{msgs['msg.form.erro.nomeempty']}">
							<p:ajax event="blur" />
						</p:inputText>
					</p:column>
					<p:column>
						<h:outputLabel for="preco"
							value="#{msgs['form.turma.label.preco']}" />
					</p:column>
					<p:column>
						<p:inputText  id="preco">
							<f:convertNumber currencySymbol="R$" maxFractionDigits="2" />
							<p:ajax event="blur" />
						</p:inputText>
					</p:column>
				</p:row>
				<p:row>
					<p:column>
						<h:outputLabel for="desc" value="Descricao:" />
					</p:column>
					<p:column colspan="2">
						<p:inputText id="desc"
							value="#{ModalidadeController.modalidade.descricao}"
							maxlength="150" />
					</p:column>
				</p:row>
			</p:panelGrid>

			<p:dataTable id="turmas" var="vturma"
				value="#{ModalidadeController.modalidade.turmas}"
				emptyMessage="#{msgs['msg.form.listaturmas.empty']}">

				<f:facet name="header">
					<h:outputText value="#{msgs['form.listaturmas.titulo']}" />
					<p:commandLink style="margin-left:12px"
						value="#{msgs['form.label.modalidade.btnAddturma']}"
						action="#{ModalidadeController.novaTurma}" process="@this"
						update=":formModalidade:dlgTurma" oncomplete="turmaDialog.show()" />
				</f:facet>
				<p:column>
					<p:rowToggler />
					<p:commandLink value="Editar" update=":formModalidade:dlgTurma"
						oncomplete="turmaDialog.show()" process="@this"
						action="#{ModalidadeController.editarTurma}">
						<f:setPropertyActionListener
							target="#{ModalidadeController.turma}" value="#{vturma}"></f:setPropertyActionListener>
					</p:commandLink>
					<br />
					<p:commandLink value="Excluir" update="turmas" process="@this"
						action="#{ModalidadeController.excluirTurma}">
						<f:setPropertyActionListener
							target="#{ModalidadeController.turma}" value="#{vturma}" />
					</p:commandLink>

				</p:column>
				<p:column headerText="Turno">
					<h:outputText value="#{vturma.turno}" />
				</p:column>

				<p:column headerText="Dias da semana">
					<h:outputText value="#{vturma.diasSemana}"
						converter="DiasSemanaConverter" />
				</p:column>

				<p:column headerText="Hora inicio">
					<h:outputText value="#{vturma.horaIn}">
						<f:convertDateTime pattern="HH:mm" />
					</h:outputText>
				</p:column>

				<p:column headerText="Hora fim">
					<h:outputText value="#{vturma.horaFin}">
						<f:convertDateTime pattern="HH:mm" />
					</h:outputText>
				</p:column>

				<p:rowExpansion>
					<p:dataList value="#{vturma.listaProfs}" var="prof">
					#{prof.professor.nome}
					</p:dataList>
				</p:rowExpansion>


			</p:dataTable>


			<p:commandButton id="addUser" value="salvar"
				action="#{ModalidadeController.salvar}" ajax="false" />

			<p:dialog id="dlgTurma" header="Turma" widgetVar="turmaDialog"
				resizable="false" showEffect="fade" hideEffect="explode"
				closable="false">

				<p:panelGrid cellpadding="10" border="0"
					rendered="#{!empty ModalidadeController.turma}">
					<p:row>
						<p:column>
							<h:outputText value="#{msgs['form.turma.label.periodo']}" />
						</p:column>
						<p:column>
							<p:selectOneRadio id="options" required="false"
								requiredMessage="#{msgs['msg.form.turma.turnoempty']}"
								value="#{ModalidadeController.turma.turno}">
								<f:selectItems value="#{ModalidadeController.listTurnos}" />
								<p:ajax event="blur" />
							</p:selectOneRadio>
						</p:column>

						<p:column>
							<h:outputText value="#{msgs['form.turma.label.horain']}" />
							<p:calendar value="#{ModalidadeController.turma.horaIn}"
								pattern="HH:mm" stepMinute="10" timeOnly="true" />
						</p:column>
						<p:column>
							<h:outputText value="#{msgs['form.turma.label.horafn']}" />
							<p:calendar value="#{ModalidadeController.turma.horaFin}"
								pattern="HH:mm" stepMinute="10" timeOnly="true" />
						</p:column>
					</p:row>
					<p:row>
						<p:column colspan="4">
							<p:selectManyCheckbox
								value="#{ModalidadeController.turma.diasSemana}">
								<f:selectItems value="#{ModalidadeController.listDiasSemanas}" />
							</p:selectManyCheckbox>
						</p:column>
					</p:row>
					<p:row>
						<p:column colspan="4">
<p:panel style="">
							<p:pickList id="profPickList"
								value="#{ModalidadeController.listaProfessores}" var="prof"
								effect="clip" itemValue="#{prof}" itemLabel="#{prof.nome}"
								showSourceControls="false" showTargetControls="false"
								showCheckbox="true" showSourceFilter="true"
								converter="#{UsuarioConverter}" showTargetFilter="true"
								filterMatchMode="contains">

								<p:ajax event="transfer"
									listener="#{ModalidadeController.onTransfer}" />

								<f:facet name="sourceCaption">Lista de Professores</f:facet>
								<f:facet name="targetCaption">Professores da turma</f:facet>

								<p:column style="width:75%;">  
         							   #{prof.nome}  
        						</p:column>

							</p:pickList>
							</p:panel>
						</p:column>

					</p:row>

					<p:row>
						<p:column colspan="3">
							<p:commandButton value="#{msgs['form.turma.label.btnadd']}"
								ajax="true" process="dlgTurma" oncomplete="turmaDialog.hide()"
								action="#{ModalidadeController.addTurma}"
								update="turmas dlgTurma" />
							<p:commandButton value="#{msgs['form.turma.label.btncancel']}"
								ajax="true" process="@this" oncomplete="turmaDialog.hide()"
								update="turmas dlgTurma">
								<f:setPropertyActionListener
									target="#{ModalidadeController.turma}" value="#{null}" />
							</p:commandButton>
						</p:column>
					</p:row>
				</p:panelGrid>
			</p:dialog>
		</h:form>
	</ui:define>
</ui:composition>
</html>